home *** CD-ROM | disk | FTP | other *** search
- Path: lrz-muenchen.de!news
- From: watzka@stat.uni-muenchen.de (Kurt Watzka)
- Newsgroups: comp.lang.c
- Subject: Re: Help:what is wrong this code?
- Date: 10 Apr 1996 11:15:12 GMT
- Organization: Leibniz-Rechenzentrum, Muenchen (Germany)
- Distribution: world
- Message-ID: <4kg580$1ga@sparcserver.lrz-muenchen.de>
- References: <4k3p3q$n76@brahms.udel.edu> <4k4hi3$5hm@sparcserver.lrz-muenchen.de> <Pine.ULT.3.92.960409210416.383A-100000@henson.cc.wwu.edu>
- NNTP-Posting-Host: sun2.lrz-muenchen.de
-
- Norma Mathews <n9341884@henson.cc.wwu.edu> writes:
-
- >On 6 Apr 1996, Kurt Watzka wrote:
-
- >> yuehong@brahms.udel.edu (Yue-hong Zheng) writes:
- >>
- >>
- >> >Why it give me 0.0000?
- >>
- >> >#include <stdio.h>
- >> >main () {
- >> >double a=9.008;
- >> >printf("%f\n",sqrt(a));
- >> >return 0;
- >> >}
-
- >your printf specifer needs to be "%lf", not "%f", since a is a double
-
- If it were a call to scanf(), the format string for _scanning_ a
- formatted double would indeed be "%lf". The format string for
- printing either a float or a double _is_ "%f". floats and doubles
- are both converted to double when passed to a variadic function.
-
- So, as long as Yue-hong Zheng is using an ANSI C compiler, the
- problem is _not_ that "%f" is used to print a double.
-
- Kurt
- --
- | Kurt Watzka Phone : +49-89-2180-6254
- | watzka@stat.uni-muenchen.de
-
-